<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title> {$action} | {:get_opinion('title')}</title>

    <include file="Public:head"/>

</head>
<body class="skin-blue">

{:W('Common/header')}

<div class="wrapper row-offcanvas row-offcanvas-left">
    {:W('Common/sideMenu')}


    <!-- Right side column. Contains the navbar and content of the page -->
    <aside class="right-side">
        <!-- Content Header (Page header) -->


        <section class="content-header">
            <h1>
                {$action}
                <small>{:get_opinion('title')}</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="{$module_url}"><i class="fa fa-dashboard"></i> {$module}</a></li>
                <li class="active">{$action}</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">

            <div class="row">
                <div class="col-md-12">

                        <!-- /.box-header -->
                        <div class="box-body">

                                <div class="col-md-6">
                                    <div class="btn-group">
                                        <a href="{:U('Admin/Access/addnode')}">
                                            <button id="sample_editable_1_new" class="btn btn-success">
                                                <i class="icon-plus"></i>添加节点
                                            </button>
                                        </a>
                                    </div>
                                    &nbsp;
                                    <div class="btn-group">

                                        <a href="{:U('Admin/Access/rebuildAccess')}"
                                           onclick="javascript:return a_confirm()">
                                            <button type="submit" class="btn btn-danger" name="delAll" value='1'> 重建权限
                                            </button>
                                        </a>
                                    </div>
                            </div>

                            <table class="table table-striped table-bordered table-hover">
                                <thead>
                                <tr>
                                    <td>序号</td>
                                    <td>节点结构 <b title="单击分类隐藏/显示该分类下在子类">[i]</b></td>
                                    <td>节点ID</td>
                                    <td>名称</td>
                                    <td>显示名</td>
                                    <td>排序名称</td>
                                    <td>类型</td>
                                    <td>状态</td>
                                    <td width="150">操作</td>
                                </tr>
                                </thead>
                                <volist name="node" id="vo" key="k">
                                    <tr align="center" id="{$vo.id}" pid="{$vo.pid}">
                                        <td>{$k}</td>
                                        <td align="left" class="tree" style="cursor: pointer;">{$vo.fullname}</td>
                                        <td>{$vo.id}</td>
                                        <td>{$vo.name}</td>
                                        <td>{$vo.title}</td>
                                        <td edit="0" fd="sort">{$vo.sort}</td>
                                        <td>{$vo.level}</td>
                                        <td>{$vo.statusTxt}</td>
                                        <td>[ <a href="javascript:void(0);" class="opStatus" val="{$vo.status}">{$vo.chStatusTxt}</a>
                                            ] [ <a href="{:U('Admin/Access/editNode',array('id'=>$vo['id']))}"
                                                   class="edit">编辑</a> ]


                                        </td>
                                    </tr>
                                </volist>
                            </table>


                        </div>
                    </div>
                </div>

        </section>
        <!-- /.content -->
    </aside>
    <!-- /.right-side -->
</div>
<!-- ./wrapper -->

<include file="Public:foot"/>
<script>
    jQuery(document).ready(function () {

        //快捷启用禁用操作
        $(".opStatus").click(function () {
            var obj = $(this);
            var id = $(this).parents("tr").attr("id");
            var status = $(this).attr("val");
            var div = $(".success");
            var url = "{:U('Admin/Access/opNodeStatus')}";
            $.getJSON(url, {id: id, status: status}, function (json) {
                if (json.status == 1) {
                    div.fadeIn().html(json.info);
                    div.fadeOut(3000);
                    $(obj).attr("val", json.data.status).html(status == 1 ? "启用" : "禁用").parents("td").prev().html(status == 1 ? "禁用" : "启用");
                } else {
                    div.fadeIn().html(json.info);
                    div.fadeOut(3000);
                }
            });
        });

        var chn = function (cid, op) {
            if (op == "show") {
                $("tr[pid='" + cid + "']").each(function () {
                    $(this).removeAttr("status").show();
                    chn($(this).attr("id"), "show");
                });
            } else {
                $("tr[pid='" + cid + "']").each(function () {
                    $(this).attr("status", 1).hide();
                    chn($(this).attr("id"), "hide");
                });
            }
        }

        //快捷改变操作排序dblclick
        $("tbody>tr>td[fd]").click(function () {
            var inval = $(this).html();
            var infd = $(this).attr("fd");
            var inid = $(this).parents("tr").attr("id");
            if ($(this).attr('edit') == 0) {
                $(this).attr('edit', '1').html("<input class='input' size='5' id='edit_" + infd + "_" + inid + "' value='" + inval + "' />").find("input").select();
            }
            $("#edit_" + infd + "_" + inid).focus().bind("blur", function () {
                var editval = $(this).val();
                $(this).parents("td").html(editval).attr('edit', '0');
                if (inval != editval) {
                    $.post("{:U('Admin/Access/opSort')}", {id: inid, fd: infd, sort: editval});


                }
            })
        });

        $(".tree").click(function () {
            if ($(this).attr("status") != 1) {
                chn($(this).parent().attr("id"), "hide");
                $(this).attr("status", 1);
            } else {
                chn($(this).parent().attr("id"), "show");
                $(this).removeAttr("status");
            }
        });
    });
</script>
</body>
</html>